package com.lcxw.hxzbim.activemq;

import com.alibaba.fastjson.JSONObject;
import javax.annotation.Resource;
import org.apache.activemq.command.ActiveMQTopic;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Component
public class Producer {

    @Resource
    private JmsMessagingTemplate jmsMessagingTemplate;

    public void topicSend(JSONObject jsonObject){
        String topicName = "room";
        ActiveMQTopic activeMQTopic = new ActiveMQTopic(topicName);
        jmsMessagingTemplate.convertAndSend(activeMQTopic,jsonObject);
    }

    @GetMapping("/mq/test")
    public void test(){
        String topicName = "room";
        ActiveMQTopic activeMQTopic = new ActiveMQTopic(topicName);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("userId","708692390994509824");
        jsonObject.put("messType","2");
        jsonObject.put("nickName","aaa");
        jsonObject.put("message","message");
        jmsMessagingTemplate.convertAndSend(activeMQTopic,jsonObject);
    }

}
